class Counter2{
    public int count=0;
    public void add() {
        synchronized(this){
            count++;
        }
    }
    public int get(){
        return count;
    }
}
public class demo22 {
    public static int count=0;
    public static void main(String[] args) throws InterruptedException {
        Counter2 counter2=new Counter2();
//        Object locker=new Object();
        Thread t1=new Thread(()->{
            for(int i=0;i<50000;i++){
                synchronized(counter2){
                    synchronized(counter2){
                        synchronized(counter2){
                            counter2.add();
                        }

                    }

                }
            }
        });
        t1.start();
        t1.join();
        System.out.println("count="+counter2.get());
    }
}
